import random

class Word_Manager:
    def __init__(self):
        with open("words.txt","r") as words:
            self.word_list = words.read().strip().split("\n")
        self.word = self.choose_word()


    def check_right(self,input_word:str):
        if len(input_word) == 0:
            return -1


        if ((len(input_word)==5)+(input_word.isalpha())+
                (input_word in self.word_list) != 3):
            return 0

        cmp_res:list[list] = []

        for i in range(5):
            if input_word[i] == self.word[i]:
                cmp_res.append([input_word[i],0])
            elif (input_word[i] != self.word[i])+(input_word[i] in self.word) == 2:
                cmp_res.append([input_word[i],1])
            else:
                cmp_res.append([input_word[i],2])
        return cmp_res

    def choose_word(self):
        return random.choice(self.word_list)

    def win_chance(self):
        return round(random.uniform(a=89.1,b=100.0),2)


def add_word():
    quit_ = ''
    with open("words.txt","r") as words:
        word_list = words.read().strip().split("\n")
    with open("words.txt","a") as words:
        while 1:
            quit_ = input("请输入你要添加的单词:")
            if quit_ == 'q':
                break
            else:
                new_word = quit_.strip()
                if new_word.isalpha() == 0 or len(new_word)!= 5:
                    print("输入单词不合理,请更换")

                if new_word not in  word_list:
                    words.write(new_word+"\n")
                    print("添加成功！")
                else:
                    print("该单词已添加")


if __name__ == '__main__':
    add_word()
